<?php


namespace app\task\cron\coupon;

use app\common\service\coupon\CouponSyncService;
use yunwuxin\cron\Task;

class SyncQuanYiProductChannel extends Task
{

    /**
     * 配置指令.
     */
    protected function configure()
    {
        // 分 时 日 月 周
        $this->expression = '*/5 * * * *';
    }

    protected function handle()
    {
        echo 'CPS权益商品同步-开始' . PHP_EOL;
        $lockKey = 'sync_quanyi_product_channnel_lock';
        $lockVal = cache($lockKey);
        if ($lockVal) {
            echo '还在处理呢' . PHP_EOL;
            return true;
        }
        cache($lockKey, 1, 5*60);
        $service = new CouponSyncService();
        //todo 同步亿奇达v2.3.7
        $service->sync(CouponSyncService::CHANNEL_YIQIDA);

        //同步鲸充,todo v2.3.7版本暂不对接
        //$service->sync(CouponSyncService::CHANNEL_JINGCHONG);

        cache($lockKey, null);
        echo 'CPS权益商品同步-结束' . PHP_EOL;
    }
}